<template>
  <div>
    <el-container>
      <el-aside width="120px">
        <!-- 用户 -->
        <div v-if="user.isLogin">用户：{{ user.name }}</div>
        <div v-else>
          <el-button @click="$router.push('/login')">去登录</el-button>
        </div>
        <!-- 菜单 -->
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-menu-item index="/home/index">
            <i class="el-icon-s-grid"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="/home/list">
            <i class="el-icon-notebook-2"></i>
            <span slot="title">列表</span>
          </el-menu-item>
          <el-menu-item index="/home/add">
            <i class="el-icon-menu"></i>
            <span slot="title">添加</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- 二级路由出口 -->
        <keep-alive>
          <router-view></router-view>
        </keep-alive>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  computed: {
    user() {
      return this.$store.state.user
    }
  }
}
</script>

<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>